package com.ruoyi.system.service.impl;

import com.ruoyi.common.exception.GlobalException;
import com.ruoyi.compensationManagement.domain.CompensationSalarySetting;
import com.ruoyi.out.mapper.LeaveInstanceMapper;
import com.ruoyi.system.domain.LeaveType;
import com.ruoyi.system.mapper.LeaveTypeMapper;
import com.ruoyi.system.service.ILeaveTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 请假类型Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-09-24
 */
@Service
public class LeaveTypeServiceImpl implements ILeaveTypeService 
{
    @Autowired
    private LeaveTypeMapper leaveTypeMapper;
    @Autowired
    private LeaveInstanceMapper leaveInstanceMapper;

    /**
     * 查询请假类型
     * 
     * @param leaveId 请假类型主键
     * @return 请假类型
     */
    @Override
    public LeaveType selectLeaveTypeByLeaveId(String leaveId)
    {
        return leaveTypeMapper.selectLeaveTypeByLeaveId(leaveId);
    }

    /**
     * 查询请假类型列表
     * 
     * @param leaveType 请假类型
     * @return 请假类型
     */
    @Override
    public List<LeaveType> selectLeaveTypeList(LeaveType leaveType)
    {
        return leaveTypeMapper.selectLeaveTypeList(leaveType);
    }

    /**
     * 新增请假类型
     * 
     * @param leaveType 请假类型
     * @return 结果
     */
    @Override
    public int insertLeaveType(LeaveType leaveType)
    {
        return leaveTypeMapper.insertLeaveType(leaveType);
    }

    /**
     * 修改请假类型
     * 
     * @param leaveType 请假类型
     * @return 结果
     */
    @Override
    public int updateLeaveType(LeaveType leaveType)
    {
        return leaveTypeMapper.updateLeaveType(leaveType);
    }

    /**
     * 批量删除请假类型
     * 
     * @param leaveIds 需要删除的请假类型主键
     * @return 结果
     */
    @Override
    @Transactional
    public int deleteLeaveTypeByLeaveIds(String[] leaveIds)
    {
        //判断id是否被sys_user表引用
        int count = leaveInstanceMapper.selectLeaveInstanceCountByLeaveIds(leaveIds);
        if(count > 0){
            throw new GlobalException("删除的请假类型已被使用");
        }
        return leaveTypeMapper.deleteLeaveTypeByLeaveIds(leaveIds);
    }

    /**
     * 删除请假类型信息
     * 
     * @param leaveId 请假类型主键
     * @return 结果
     */
    @Override
    public int deleteLeaveTypeByLeaveId(String leaveId)
    {
        return leaveTypeMapper.deleteLeaveTypeByLeaveId(leaveId);
    }
}
